package ${package.Controller};

import com.life.xxx.util.Page;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;

import ${package.Entity}.${table.entityName};
import ${package.Service}.${table.serviceName};

/**
* <p>
    * ${table.comment!} 前端控制器
    * </p>
*
* @author ${author}
* @since ${date}
*/
@RestController
@RequestMapping("/<#if controllerMappingHyphenStyle>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
public class ${table.controllerName} {

    @Autowired
    private ${table.serviceName} ${table.serviceName?uncap_first};

    /**
    * 获取所有数据
    */
    @GetMapping
    public List<${table.entityName}> getAll() {
        return ${table.serviceName?uncap_first}.list();
    }

    /**
    * 根据 ID 获取数据
    */
    @GetMapping("/{id}")
    public ${table.entityName} getById(@PathVariable("id") Long id) {
        return ${table.serviceName?uncap_first}.getById(id);
    }

    /**
    * 分页查询
    */
    @GetMapping("/page")
    public Page<${table.entityName}> getPage(Page<${table.entityName}> page,${table.entityName} ${table.entityName?uncap_first}) {
        return ${table.serviceName?uncap_first}.queryByPage(page,${table.entityName?uncap_first});
    }

    /**
    * 创建数据
    */
    @PostMapping
    public boolean create(@RequestBody ${table.entityName} ${table.entityName?uncap_first}) {
        return ${table.serviceName?uncap_first}.save(${table.entityName?uncap_first});
    }

    /**
    * 更新数据
    */
    @PutMapping
    public boolean update(@RequestBody ${table.entityName} ${table.entityName?uncap_first}) {
        return ${table.serviceName?uncap_first}.updateById(${table.entityName?uncap_first});
    }

    /**
    * 删除数据
    */
    @DeleteMapping("/{id}")
    public boolean delete(@PathVariable("id") Long id) {
        return ${table.serviceName?uncap_first}.removeById(id);
    }
}